import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/public/el-form.vue"; //弹框form
import TableData from "@/components/public/el-tables"; //主页面列表


import {
    getMachineCheckListByFid, //查看详情

} from "@/api/request.js";

export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
        "fCompanyid",
        "fCompanyname",
        "modelType",
        "isclose"
    ],
    data() {
        return {
            table_config: formJs.table_config, 
            tableData: [], //材料用量列表
            formObj:formJs.formObj,
            formData:{},
            fSourcefileList_dialog:[]

        };
    },
    components: {
        publicForm,
        TableData

    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        modelType: {
            handler(newVal) {
                if (newVal) {
                    this.modelTypes = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {


                    this.edit(newVal);
                }

            },
            immediate: true,
        },

        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
     

                    if (this.statusNum != 1) {
                        this.getDetail({
                         
                            fId: this.currentDetail.fId
                        }) // currentRow
                    }
                }
            },

            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {

                    this.fCompanyids = newVal

                }
            },
            immediate: true,
        },
        fCompanyname: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal

                }
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },

    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("monitorBack-userInfo"));

        this.btnShow = true

        // this.handNum = true; //闭合申请单
        // this.firstNum = true; //一级审核
        // if (this.statusNum == 1) { //新增
        //     this.getDetail({
        //         fId: ""
        //     })
        //     this.formObj.map((item) => {
        //         item.disabled = false;
        //     });
        //     this.disabled = false;
        //     this.formObjText.map((item) => {
        //         item.disabled = false;
        //     });
        //     this.formObjText[0].disabled = true;
        //     this.formObjText[3].uploadSelect = true
        //     this.formObj[5].inputButton = true;
        //     this.formObjText[2].inputButton = true;

        //     this.isEdit = false
        // } else if (this.statusNum == 2) { //编辑
        //     this.disabled = false;
        //     this.formObj.map((item) => {
        //         item.disabled = false;
        //     });
        //     this.formObj[5].inputButton = true;

        //     this.formObjText.map((item) => {
        //         item.disabled = false;
        //     });
        //     this.formObjText[2].inputButton = true;

        //     this.formObjText[0].disabled = true;
        //     // this.formObj[3].disabled = true;
        //     this.formObjText[3].uploadSelect = true
        //     this.isEdit = false

        // } else 
        if (this.statusNum == 7) { //查看
            this.btnShow = false
            this.disabled = true;
            // 闭合
            // this.formObj.map((item) => {
            //     item.disabled = true;
            // });
            // this.formObj[5].inputButton = false;

            // this.formObjText.map((item) => {
            //     item.disabled = true;
            // });
            this.isEdit = true
            // this.formObjText[2].inputButton = false;

            // this.formObjText[3].uploadSelect = false
        }
        this.getHeight();
    },
    methods: {
        // 选择工程部位
        refreshList() {},
        engineeringLocationDialog() {
            this.engineeringLocationShow = false;
        },
        getEngineeringLocation(data) { //获取材料信息
            this.formData.fEnginerringpart = data.F_TreeName; // 报验工程部位
        },
        // 选择工程部位
        // 选择人
        personDialog() {
            this.personShow = false;
        },
        getperson(data) { //单选

            this.selectArr = data;
            this.formData.fAppointstationtesterid = data.fUserid;
            this.formData.fAppointstationtestername = data.fRealname;
        },
        // 选择人
        // 折叠面板
        changeCollapse(e) {
            console.log(this.activeNames, e);
        },
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },

        edit() {
            this.closeFormData = this.$options.data.call(this).closeFormData;
        },
      // 点击当前
      rowChange(val) {
        console.log(val);
        // this.row = val;
        // this.fId = val.fId;
      },
      rowChange_dialog(val) {
        this.formData = val;
        this.fSourcefileList_dialog = this.formData.scanFileList;
        // this.fId_dialog = val.fId;
      },


        // 详情
        getDetail(obj) {
            this.loading=true;
            getMachineCheckListByFid(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = false;
                        this.tableData = res.data.machineCheckList;
                        if ( this.tableData.length != 0) {
                        this.formData = this.tableData[0];
                        this.fSourcefileList_dialog = this.formData.scanFileList;
                        }
                    } else {
                        this.$message.error(res.msg);
                        this.loading = false;
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("拌合站设置编辑报错", error);
                });

        },
  

    },
};